var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var ResKeeper = require("AA_ResKeeper");
var Excel = require("AA_Excel");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var NodePoolMag = require("AA_NodePoolMag");
var BuffMag = require("AA_BuffMag");
var UI_MosterLogic = require("AA_UI_MosterLogic");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_BulletBang = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.bulletId = 1;
    t.gunzi = null;
    t.attack = 0;
    t.isbaoji = false;
    t.attackfang = null;
    t.attacktype = 1;
    t.isbisha = false;
    t.nowtagMoster = null;
    t.nowdirection = 0;
    t.tuoweiNode = null;
    t.defmosterX = 0;
    t.defmosterY = 0;
    t.nowbuffdata = null;
    t.tagMosterX = 0;
    t.tagMosterY = 0;
    t.isshua = false;
    t.tuoweiscale = 0;
    t.stoptime = 10;
    t.bulletspeed = 20;
    t.issend = false;
    t.jiangetime = .4;
    t.leijitime = 0;
    t.ismove = false;
    t.attackcount = 0;
    t.addtime = 0;
    t.isover = false;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.initBullet = function (e, t) {
    return __awaiter(this, undefined, undefined, function () {
      var o;
      var n;
      return __generator(this, function () {
        this.attackcount = 0;
        this.attack = e.attack;
        this.isshua = false;
        this.attackfang = e.playerId;
        this.attacktype = e.feixintype;
        this.isbaoji = e.isbaoji;
        this.nowtagMoster = t;
        o = cc.v2();
        this.defmosterX = this.nowtagMoster.x;
        this.defmosterY = this.nowtagMoster.y;
        cc.Vec2.subtract(o, cc.v2(this.defmosterX, this.defmosterY), this.node.getPosition());
        this.nowdirection = Math.atan2(o.y, o.x);
        this.addtime = 0;
        this.issend = true;
        n = Excel.Excel.shuiguo(this.attackfang.playerId + 1e3);
        this.nowbuffdata = Excel.Excel.shuiguobuff(n.talent);
        this.jiangetime = this.nowbuffdata.value[3];
        this.stoptime = this.nowbuffdata.bufftime;
        if (4 == this.attackfang.playerInfo.equipLevel) {
          this.node.children[1].active = true;
          this.node.children[0].active = false;
        } else {
          this.node.children[1].active = false;
          this.node.children[0].active = true;
        }
        this.isover = false;
        return [2];
      });
    });
  };
  _creator.prototype.getNowTime = function () {
    var e = BuffMag.BuffMgr.getFanBei();
    return this.stoptime + this.stoptime * e;
  };
  _creator.prototype.onDisable = function () {};
  _creator.prototype.getBulletAttack = function () {
    return this.attack * this.nowbuffdata.value[0] / 100;
  };
  _creator.prototype.sendBullet1 = function (e) {
    this.moveBullet(this.nowdirection, e);
  };
  _creator.prototype.moveBullet = function (e) {
    this.node.x += Math.cos(e) * this.bulletspeed;
    this.node.y += Math.sin(e) * this.bulletspeed;
    if (cc.Vec2.distance(cc.v2(this.defmosterX, this.defmosterY), this.node.getPosition()) <= 25) {
      this.hitMoster();
      this.issend = false;
    }
  };
  _creator.prototype.getBiSha = function () {
    this.isbisha = BuffMag.BuffMgr.getLajiaoBiSha(this.attackfang, GameGlobalVariable.GameGlobalVariable.wukongbishabili);
    return this.isbisha;
  };
  _creator.prototype.hideBullet = function () {
    if (!this.isover) {
      this.isover = true;
      this.issend = false;
      NodePoolMag.NodePoolMag.instance.recycleNode("bullet_" + this.bulletId, this.node);
    }
  };
  _creator.prototype.getNowMosterNode = function (e) {
    var t = GameGlobalVariable.GameGlobalVariable.mosterNode.children;
    var o = [];
    for (var n = 0; n < t.length; n++) {
      var i = t[n];
      var a = cc.Vec2.distance(i.getPosition(), this.node.getPosition());
      (a -= i.width / 2 + this.node.width / 2) <= e && o.push(i);
    }
    return o;
  };
  _creator.prototype.getBulletSpeed = function () {
    this.bulletspeed = this.bulletspeed * GameGlobalVariable.GameGlobalVariable.jiasuState;
    return this.bulletspeed;
  };
  _creator.prototype.hitMoster = function () {
    this.attackcount++;
    var e = this.getNowMosterNode(50);
    var t = e.length;
    t > 4 && (t = 4);
    for (var o = 0; o < t; o++) {
      var n = e[o].getComponent(UI_MosterLogic.default);
      n.beAttack(this);
      n.setPuTongJianShu(this.nowbuffdata);
      if (this.attackfang.playerInfo.equipLevel >= 4) {
        var i = n.xueliang;
        var a = Excel.Excel.shuiguobuff(89);
        var r = i * a.value[0] / 100;
        r > this.attack * a.value[3] && (r = this.attack * a.value[3]);
        n.fujiaAttack(r, 1, this);
      }
    }
  };
  _creator.prototype.onUpdate = function (e) {
    if (!this.ismove) {
      this.leijitime += e;
      if (this.leijitime > this.jiangetime) {
        this.hitMoster();
        console.log("攻击次数", this.attackcount, this.leijitime);
        this.leijitime = 0;
      }
      if (!this.issend) {
        this.addtime += e;
        this.addtime > this.stoptime && this.hideBullet();
        return void GameGlobalVariable.GameGlobalVariable.playHitgunzi();
      }
      this.sendBullet1(e);
    }
  };
  __decorate([_property()], _creator.prototype, "bulletId", undefined);
  __decorate([_property(dragonBones.ArmatureDisplay)], _creator.prototype, "gunzi", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_BulletBang;